package com.xdkj.model.dao.impl;

import com.xdkj.commons.util.RunnerUtil;
import com.xdkj.model.dao.TPositionDao;
import com.xdkj.model.entity.TPosition;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * ClassName TDepartmentDaoImpl
 * Description:
 *
 * @Author:一尘
 * @Version:1.0
 * @Date:2021-11-05-10:16
 */
public class TPositionDaoImpl implements TPositionDao {
    private QueryRunner runner = RunnerUtil.getRunner();

    @Override
    public List<TPosition> queryAll() {
        List<TPosition> list = null;
        try {
            list = runner.query("select * from t_position", new BeanListHandler<>(TPosition.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }

    @Override
    public TPosition queryByName(String name) {
        TPosition tPosition = null;
        try {
            tPosition = runner.query("select * from t_position where name = ? ", new BeanHandler<>(TPosition.class), name);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return tPosition;
    }
}
